import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/model/pro_detail_model/pro_detail_model.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/model/pro_enterprise_model.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_base_info/state.dart';
import 'package:jinke/utils/util.dart';
import 'package:url_launcher/url_launcher_string.dart';

class ProBaseInfoController extends GetxController {
  ProBaseInfoController();
  final state = ProBaseInfoState();

  void setupPro() {
    state.pros = [
      BrnInfoModal(keyPart: '项目专员:', valuePart: state.mod?.createByName),
      BrnInfoModal(keyPart: '项目简称:', valuePart: state.mod?.projectAlias),
      BrnInfoModal(keyPart: '项目内容:', valuePart: state.mod?.projectContent),
      BrnInfoModal(
          keyPart: '投资额:', valuePart: '${state.mod?.investmentQuota ?? ''}亿元'),
      BrnInfoModal(
          keyPart: '用工人数:', valuePart: '${state.mod?.employmentNumber ?? 0}人'),
      BrnInfoModal(keyPart: '所属产业:', valuePart: '重大项目'),
    ];
  }

  void setupEnterprise() {
    state.enterprises = [
      BrnInfoModal(
          keyPart: '企业名称:', valuePart: state.enterprise?.enterpriseName),
      BrnInfoModal(
          keyPart: '企业简介:', valuePart: state.enterprise?.enterpriseAlias),
      BrnInfoModal(keyPart: '企业类型:', valuePart: '国企'),
      BrnInfoModal(
          keyPart: '来源地:', valuePart: state.enterprise?.enterpriseCity),
      BrnInfoModal(keyPart: '联系人:', valuePart: state.enterprise?.linkPerson),
      BrnInfoModal(
          keyPart: '联系电话:',
          valuePart: InkWell(
            onTap: () {
              launchUrlString("tel://${state.enterprise?.linkPhone ?? ""})");
            },
            child: Container(
                child: Row(
              children: [
                Text(
                  state.enterprise?.linkPhone ?? '',
                  style: TextStyle(color: ColorsUtil.blue, fontSize: 14.r),
                ),
                Icon(
                  Icons.phone,
                  color: ColorsUtil.blue,
                  size: 15.r,
                )
              ],
            )),
          )),
    ];
  }

  void setupInfos() {
    var info = state.enterprise?.objInfos;
    state.infos = info
        ?.map((e) =>
            BrnInfoModal(keyPart: e.name ?? '', valuePart: e.content ?? ''))
        .toList();
  }

  initData() {
    setupPro();
    setupEnterprise();
    setupInfos();
    _update();
  }

  void _update() {
    update(["pro_base_info"]);
  }

  void onTap() {}

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  @override
  void onReady() {
    super.onReady();
    initData();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }
}
